﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.ObjectBuilder2;
using Churchtoolkit.DataAccess.Repositories;
using Churchtoolkit.DataAccess.Entities;
using Churchtoolkit.DataAccess.Common;
using Churchtoolkit.Utils.MVP;
using Churchtoolkit.Utils.Navigation;

namespace Churchtoolkit.Shell.Views
{
    public class RegistrationViewPresenter : Presenter<IRegistrationViewView>
    {
        private MembersRepository _NewMember;

        public RegistrationViewPresenter(MembersRepository memberRepository)
        {
            _NewMember = memberRepository;
        }
        
        /// <summary>
        /// Saves the specified new member.
        /// </summary>
        /// <param name="newMember">The new member.</param>
        /// <returns></returns>
        public void Save()
        {
            _NewMember.Insert(this.View.CurrentMember);
            Navigator.NavigateTo(Pages.Shared_Message, "code=0001");
        }
        /// <summary>
        /// Determines whether the specified email is unique.
        /// </summary>
        /// <param name="email">The email.</param>
        /// <returns>
        /// 	<c>true</c> if the specified email is unique; otherwise, <c>false</c>.
        /// </returns>
        public bool IsUnique(string email)
        {
            EntityResult<Members> similarEmails;
            similarEmails = _NewMember.Find(items => items.Email = email);
            if (similarEmails.RowsCount==0)
                return true;
            return false;
        }

    }
}




